﻿using System.Windows;
using Ops.Mpc.Controllers;

namespace Ops.Mpc.States
{
    public class CallStateActionStateAction : StateAction
    {
        public static readonly DependencyProperty NextStateActionItemNameProperty = DependencyProperty.Register("NextStateActionItemName", typeof(string), typeof(CallStateActionStateAction), null);
        public string NextStateActionItemName
        {
            get
            {
                return (string)this.GetValue(NextStateActionItemNameProperty);
            }

            set
            {
                this.SetValue(NextStateActionItemNameProperty, value);
            }
        }

        protected override void OnExecute(object context)
        {
            base.OnExecute(context);

            this.Finish();
        }

        protected override void MoveToNextState()
        {
            IStateAction iStateAction = this.GetNextStateAction();

            if (iStateAction != null)
                iStateAction.Execute(this.Controller, new ActionResultCallback(new ActionResultCallback(OnStateActionComplete)));
        }

        private void OnStateActionComplete(ActionResult actionResult)
        {

        }

        protected IState GetCurrentState()
        {
            IController iController = this.Controller;
            
            if (iController != null)
                return iController.CurrentState;
            else
                return null;
        }

        protected IStateAction GetNextStateAction()
        {
            IState iState = this.GetCurrentState();

            if (iState != null)
                return iState.GetStateAction(this.NextStateActionItemName, true);
            else
                return null;
        }
    }
}
